@echo off

set ROOT=%~dp0
set EXTERNALS=externals
set DOWNLOAD=%ROOT%tools\wget.exe --continue -P %EXTERNALS%
set EXTRACT=%ROOT%tools\7za.exe x -y
set DEL=del /Q

call tools\externals_info.cmd

set SKIP_DOWNLOAD=0

if NOT EXIST %EXTERNALS% mkdir %EXTERNALS%

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo Downloading External libs
if %SKIP_DOWNLOAD% == 1 goto label_extraction

%DOWNLOAD% %BZIP2_URL%
%DOWNLOAD% http://zlib.net/zlib125.zip
%DOWNLOAD% %BOOST_URL%
::%DOWNLOAD% %TBB_URL%
%DOWNLOAD% %GTEST_URL%
%DOWNLOAD% %GPB_URL%

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:label_extraction
pushd %EXTERNALS%

echo Extracting bzip2...
%EXTRACT% %BZIP2_FILE%.tar.gz > nul
%EXTRACT% %BZIP2_FILE%.tar > nul

echo Extracting zlib...
%EXTRACT% zlib125.zip > nul

echo Extracting boost...
%EXTRACT% %BOOST_FILE% > nul

echo Extracting tbb...
::%EXTRACT% %TBB_FILE%.tgz > nul
::%EXTRACT% %TBB_FILE%.tar > nul

echo Extracting gtest...
%EXTRACT% %GTEST_FILE%.zip > nul

echo Extracting Google Protocol Buffers...
%EXTRACT% %GPB_FILE%.zip > nul

echo Renaming folders...
rename %BZIP2_FILE% bzip2
rename zlib-1.2.5 zlib
rename %BOOST_FILE_NAME% boost
rename %GTEST_FILE% gtest

echo Deleting files...
%DEL% %BZIP2_FILE%.tar
%DEL% %TBB_FILE%.tar

::echo Building externals...
::pushd build
::call build_externals.cmd
::popd

echo Done.

popd
